﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Isuka.Iteration;

namespace Isuka.Spiritual
{
    public abstract class Grammer<T, A>
        : Rules<T, A>
        , IGrammer<T, A>
        where T : IEquatable<T>
        where A : class
    {
        #region IGrammer<T,A> メンバー

        public IRule<T, A> Rule
        {
            get;
            protected set;
        }

        public Rules<T, A>.SkipFunc Skipper
        {
            get;
            set;
        }

        public RuleResult<T> Run(IBidirectionalIterator<T> it, RuleContext<T, A> context)
        {
            return Rule.Rule(it, context, Skipper ?? NoSkip);
        }

        #endregion

        #region IRule<T,A> メンバー

        Rules<T, A>.RuleFunc IRule<T, A>.Rule
        {
            get { return Rule.Rule; }
        }

        #endregion
    }

    public abstract class CharGrammer<A>
        : CharRules<A>
        , IGrammer<char, A>
        where A : class
    {
        #region IGrammer<char,A> メンバー

        public IRule<char, A> Rule
        {
            get;
            protected set;
        }

        public Rules<char, A>.SkipFunc Skipper
        {
            get;
            set;
        }

        public RuleResult<char> Run(IBidirectionalIterator<char> it, RuleContext<char, A> context)
        {
            return Rule.Rule(it, context, Skipper ?? NoSkip);
        }

        #endregion

        #region IRule<char,A> メンバー

        Rules<char, A>.RuleFunc IRule<char, A>.Rule
        {
            get { return Rule.Rule; }
        }

        #endregion
    }
}
    